package com.ext.aic.adapter;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.ext.aic.beans.SecondIndustry;
import com.ext.aic.beans.TabItem;
import com.ext.aic.fragment.IndustryListFragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.Setter;

@Setter
public class GettingCustomersPagerAdapter extends FragmentPagerAdapter {

    private List<TabItem> tabItems=new ArrayList<>();
    private Map<Integer, List<SecondIndustry>> industryMap = new HashMap<>();

    public GettingCustomersPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public void addItem(TabItem tabItem){
        tabItems.add(tabItem);
    }

    @Override
    public Fragment getItem(int position) {
        IndustryListFragment fragment = new IndustryListFragment();
        List<SecondIndustry> industries = industryMap.get(position);
        fragment.setItems(industries == null ? new ArrayList<>() : industries);
        return fragment;
    }

    @Override
    public int getCount() {
        return tabItems.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        TabItem tabItem = tabItems.get(position);
        return tabItem.getLabel();
    }
}
